"""Superclass for routing models.

Copyright (C) Sarah Mount 2008.

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
"""

from __future__ import absolute_import
del absolute_import

from ..modelManager import Model
# from .. import radioInterface
# Eventually, we'll need 'send' and 'receive' functions that are
# either a real link to a real radio or a model of a radio.

import time

class RoutingModel(Model):
    """Superclass for all Routing models.
    This model has responsibility for managing the send_q and recv_q
    data structures within the sensor type.
    """
    def __init__(self):
        self.modeltype = 'Routing'
	self.send_q = None
	"""@ivar: thread-safe queue for messages to send. Set by sensor objects."""
	self.recv_q = None
	"""@ivar: thread-safe queue for received messages. Set by sensor objects."""
	self.radio = None # TODO!
	"""@ivar: radio interface (real or simulated)."""
	self.sensor_id = None 
	"""@ivar: id of the sensor for which this object is the routing layer."""
        return
    def send(self, arc_colour):
        """Send a single packet.
        Must be overridden all in subclasses.
        """
        return
    def receive(self):
        """Process received packets.
        Must be overridden all in subclasses.
        *** Should this be a generator?
        """
        return
    def sendAll(self, arc_colour):
        """Send all packets currently in the send queue.
        """
        if not self.send_q.empty():
            self.send(arc_colour)
        return
    def clock(self):
        """Report the current time (as a float).

	TODO: WILL BE REPLACED BY TIME MODEL.
        Time is taken from the processor and should be accurate to
        the nearest millisecond.
        To simulate clock drift; override this method and add a
        random value to the result of time.clock().

        @rtype: float
        """
        return time.clock()

